package com.budwk.app.sqfwV2.enums.dayingRoad;

import com.budwk.app.sqfwV2.dto.dto.centuryCity.SafeCheckTaskParamDataDTO;
import com.budwk.app.sqfwV2.dto.dto.dayingRoad.ProblemBaseVo;
import com.budwk.app.sqfwV2.enums.RectificateTimeEnum;
import lombok.Getter;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 其余巡查内容25个问题默认值
 */
@Getter
public enum OtherPatrolContentsEnum {

    ONE("1","usingGasSemiSpaces", "false", "在地下或半地下空间、高层建筑内使用瓶装燃气"), //
    TWO("2","storageGasRoom", "false", "存放气瓶总重量超过100kg未设置专用气瓶间"),
    THREE("3","inUseGasSpare", "false", "在用气瓶和备用气瓶未分开放置"),//3
    FORE("4","theHoseMeters", "false", "燃气连接软管长度超过2米"),//4
    FIVE("5","rubberHosesDoors", "false", "橡胶软管私接“三通”或连接软管穿越墙体、门"),//5
    SIX("6","useMoreSources", "false", "使用两种以上“火源”"),//6
    SEVEN("7","improperAlarmDevices", "false", "未规范安装、使用燃气泄漏报警装置及燃气紧急切断阀"),//7
    ENGHT("8","illegalStorageFuels", "false", "违规存储，使用工业醇基燃料"),//8
    NINE("9","indoorParkingBicycles", "false", "电动自行车室内停放、充电"),//9
    TEN("10","electricalLaidMaterials", "false", "电气线路敷设在易燃、可燃材料上"),//10
    ELEVEN("11","blockedSafetyExits", "false", "安全出口堵塞、锁闭"),//11
    TWELVE("12","stackingDebrisRoutes", "false", "疏散通道、楼梯间堆放杂物"),//12
    THIRTEEN("13","settingNetsWindow", "false", "外窗违规设置防盗网或铁栅栏"),//13
    FORETEEN("14","notEquippedFire", "false", "未配备灭火器"),//14
    FIVETEEN("15","operatorsFires", "false", "经营者或员工不会组织扑救初起火灾或不会组织疏散逃生"),//15
    SIXTEEN("16","isDeviceField", "true", "用气场所是否安装通风装置"),//16
    SEVENTEEN("17","usingCylindersLabels", "false", "使用无警示标签、无充装标识、过期或者报废钢瓶"),//17
    EIGHTTEEN("18","theDistanceGasMeters", "true", "液化石油气瓶与火源距离1.5米"),//18
    NINETEEN("19","useHeatingCylinders", "false", "使用加热装置加热液化石油气瓶。(加热带、热水等)"),//19
    TWENTY("20","horizontalGasCylinder", "false", "横瓶倒置液化石油气瓶"),//20
    TWENTYONE("21","isRubberHoseRecorded", "true", "是否定期更换胶管(不少于一年一换)并记录"),//21
    TWENTYTWO("22","unauthorizedCylinders", "false", "擅自拆除、改装液化石油气瓶"),//22
    TWENTYTHREE("23","isNecessaryLeakCylinde", "true", "液化气瓶更换时是否签署查漏签收并试通气"),//23
    TWENTYFORE("24","doUsersPurchase", "true", "燃气用户是否购买相关保险"),//24
    TWENTYFIVE("25","doesSupplyCarry", "true", "供气企业是否开展入户安检及安培");//25

    private final String number;

    private final String code;

    private final String defaultValue;

    private final String desc;

    OtherPatrolContentsEnum(String number, String code, String defaultValue, String desc) {
        this.number = number;
        this.code = code;
        this.defaultValue = defaultValue;
        this.desc = desc;
    }

    /**
     * 获取25个问题的默认值
     * @return
     */
    public static Map<String, String> otherPatrolContentsDefaultValue() {
        Map<String, String> map = Arrays.stream(values()).collect(Collectors.toMap(OtherPatrolContentsEnum::getCode, OtherPatrolContentsEnum::getDefaultValue));
        return map;
    }

    public static String getDesc(String code) {
        Optional<OtherPatrolContentsEnum> optional = Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst();
        return optional.orElseGet(null).getDesc();
    }

    /**
     * 获取问题编号
     */
    public static OtherPatrolContentsEnum getEnumByCode(String code) {
        Optional<OtherPatrolContentsEnum> optional = Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst();
        return optional.orElse(null);
    }

    /**
     * 前端传递的参数 如果和默认值不一致并是限期整改的 返回描述信息
     */
    public static List<String> getProblemDesc(List<SafeCheckTaskParamDataDTO> others) {
        List<String> list = new ArrayList<>();
        for (SafeCheckTaskParamDataDTO other : others) {
            OtherPatrolContentsEnum industriesEnum = getEnumByCode(other.getFields());
            // 判断是否为限期整改
            if (RectificateTimeEnum.isDeadlineRectification(other, industriesEnum.getDefaultValue())) {
                list.add(industriesEnum.getDesc());
            }
        }
        return list;
    }

    /**
     * 前端传递的参数 如果和默认值不一致 返回描述信息
     */
    public static List<String> getInconsistentWithDefaultValues(List<SafeCheckTaskParamDataDTO> others) {
        List<String> list = new ArrayList<>();
        for (SafeCheckTaskParamDataDTO other : others) {
            OtherPatrolContentsEnum industriesEnum = getEnumByCode(other.getFields());
            if (other.getKey().equals(industriesEnum.getDefaultValue())) {
                continue;
            }
            list.add(industriesEnum.getDesc());
        }
        return list;
    }

    /**
     * 获取前15个问题的code
     */
    public static List<OtherPatrolContentsEnum> getFrontFifteenQuestion() {
        List<OtherPatrolContentsEnum> codes = List.of(OtherPatrolContentsEnum.ONE, OtherPatrolContentsEnum.TWO,
                OtherPatrolContentsEnum.THREE, OtherPatrolContentsEnum.FORE,
                OtherPatrolContentsEnum.FIVE, OtherPatrolContentsEnum.SIX,
                OtherPatrolContentsEnum.SEVEN, OtherPatrolContentsEnum.ENGHT,
                OtherPatrolContentsEnum.NINE, OtherPatrolContentsEnum.TEN,
                OtherPatrolContentsEnum.ELEVEN, OtherPatrolContentsEnum.TWELVE,
                OtherPatrolContentsEnum.THIRTEEN, OtherPatrolContentsEnum.FORETEEN,
                OtherPatrolContentsEnum.FIVETEEN);
        return codes;
    }

    /**
     * 设置默认值 并返回对象
     */
    public static List<SafeCheckTaskParamDataDTO> getAllDefaults() {
        List<SafeCheckTaskParamDataDTO> list = new ArrayList<>();
        Arrays.stream(values()).forEach(e -> list.add(initData(e)));
        return list;
    }

    /**
     * 获取问题默认值 组装ProblemBaseVo对象
     */
    public static List<ProblemBaseVo> getProblemBaseVoDefaults() {
        List<ProblemBaseVo> list = new ArrayList<>();
        Arrays.stream(values()).forEach(e -> {
            ProblemBaseVo vo = new ProblemBaseVo();
            list.add(vo.setCode(e.getCode()).setDefaultValue(e.getDefaultValue()).setDesc(e.getDesc()).setNumber(e.getNumber()));
        });
        return list;
    }

    public static SafeCheckTaskParamDataDTO initData(OtherPatrolContentsEnum fEnum) {
        SafeCheckTaskParamDataDTO s = new SafeCheckTaskParamDataDTO();
        s.setFields(fEnum.getCode()).setKey(fEnum.getDefaultValue()).setRiskDesc(fEnum.getDesc()).setRiskCode(fEnum.getNumber());
        return s;
    }

}
